package com.itheima.health.h5.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderService;
import com.itheima.health.utils.redis.RedisUtil;
import com.itheima.health.utils.resources.RedisMessageConstant;
import com.itheima.health.utils.sms.ValidateCodeUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
public class OrderController {

    @Reference
    private OrderService orderService;

//    @Autowired
//    private RabbitTemplate rabbitTemplate;


    @GetMapping("order/sendMessage/{telephone}")
    public Result sendMessage(@PathVariable("telephone") String telephone){
        String code = ValidateCodeUtils.generateValidateCode(4);
        //  存放 redis    阿里云发送短信
        RedisUtil.set(RedisMessageConstant.SENDTYPE_ORDER+telephone,code,30, TimeUnit.SECONDS);
//        SmsUtils.validUserTelephone(telephone,code);
//        Map map= new HashMap();
//        map.put("telephone",telephone);
//        map.put("code",code);
//        rabbitTemplate.convertAndSend("heima-queue",map);
        System.out.println(code);
        return new Result(code);
    }

    @PostMapping("order/add")
    public Result add(@RequestBody Map map){
        return new Result(orderService.add(map));
    }

    @GetMapping("order/findOrderInfoById/{id}")
    public Result findOrderInfoById(@PathVariable("id") Integer id ){
        return new Result(orderService.findOrderInfoById(id));
    }
}
